<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('文章列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="notice-form">
					<div class="select-list">
						<ul>
							<li>
								文章标题：<input type="text" name="articleTitle"/>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="sys:article:add" >
		            <i class="fa fa-plus"></i> 新增
		        </a>
	        </div>
	        <div class="col-sm-12 select-table table-striped">
	            <table id="bootstrap-table" data-mobile-responsive="true"></table>
	        </div>
    	</div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('sys:article:edit')}]];
		var delFlag = [[${@permission.hasPermi('sys:article:del')}]];
		var preFlag = [[${@permission.hasPermi('sys:article:preFlag')}]];
		var topFlag = [[${@permission.hasPermi('sys:article:top')}]];
		var relFlag = [[${@permission.hasPermi('sys:article:rel')}]];
        var prefix = "/sys/article";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
				detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/deleteById",
                modalName: "文章",
                columns: [{
		            checkbox: true
		        },
				{
					title : '序号' ,
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
				{
					field : 'articleTitle',
					title : '文章标题'
				},
				{
					field : 'columnName',
					title : '所属栏目'
				},
				{
		            field: 'releaseTime',
		            title: '发布时间',
					formatter: function(value,row,index){
						return $.dateUtil.toDateString(row.releaseTime,"yyyy-MM-dd");
					}
		        },
				{
		            field: 'releaseStatus',
		            title: '发布状态',
		            align: 'center',
		            formatter: function(value, row, index) {
						if (row.releaseStatus == 0) {
							return '未发布';
						} else {
							return '已发布';
						}
		            }
		        },
					{
						field: 'topStatus',
						title: '置顶状态',
						align: 'center',
						formatter: function(value, row, index) {
							if (row.topStatus == 0) {
								return '未置顶';
							} else {
								return '已置顶';
							}
						}
					},
				{
					field : 'chickNum',
					title : '浏览次数'
				},
				{
					field : 'createName',
					title : '创建者' 
				},
				{
		            field: 'lastModifyTime',
		            title: '最后修改时间',
		            sortable: true,
					formatter: function(value,row,index){
		            	return $.dateUtil.toDateString(row.lastModifyTime,"yyyy-MM-dd");
					}
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						var articleId = "articleId";
						if (row.releaseStatus == 0) {
							actions.push('<a class="btn btn-success btn-xs ' + relFlag + '" href="javascript:void(0)" onclick="enableRelease(\'' + row.articleId + '\')"><i class="fa fa-refresh"></i>发布</a> ');
						} else {
							actions.push('<a class="btn btn-danger btn-xs ' + relFlag + '" href="javascript:void(0)" onclick="disableRelease(\'' + row.articleId + '\')"><i class="fa fa-refresh"></i>取消发布</a> ')
						}
						if (row.topStatus == 0) {
							actions.push('<a class="btn btn-success btn-xs ' + topFlag + '" href="javascript:void(0)" onclick="enableTop(\'' + row.articleId + '\')"><i class="fa fa-refresh"></i>置顶</a> ');
						} else {
							actions.push('<a class="btn btn-danger btn-xs ' + topFlag + '" href="javascript:void(0)" onclick="disableTop(\'' + row.articleId + '\')"><i class="fa fa-refresh"></i>取消置顶</a> ')
						}
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.articleId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + preFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.articleId + '\')"><i class="fa fa-edit"></i>预览</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + delFlag + '" href="javascript:void(0)" onclick="$.operate.deleteById(\'' + articleId + '\',\'' + row.articleId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
		/* 文章管理-取消发布 */
		function disableRelease(articleId) {
			$.modal.confirm("确认要取消发布吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "articleId": articleId, "releaseStatus": 0 });
			})
		}

		/* 文章管理-发布  */
		function enableRelease(articleId) {
			$.modal.confirm("确认要发布文章吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "articleId": articleId, "releaseStatus": 1 });
			})
		}
		/* 文章管理-取消取消置顶 */
		function disableTop(articleId) {
			$.modal.confirm("确认要取消置顶吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "articleId": articleId, "topStatus": 0 });
			})
		}

		/* 文章管理-置顶  */
		function enableTop(articleId) {
			$.modal.confirm("确认要置顶文章吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "articleId": articleId, "topStatus": 1 });
			})
		}
    </script>
</body>
</html>